package com.elepro.shoppingmall.mapper.goods;

import com.elepro.shoppingmall.entity.Goods;
import com.elepro.shoppingmall.entity.GoodsType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GoodsMapper {
    //Goods
    @Insert("insert into goods(goodsName,goodsTypeId,price,describle,picture) values(#{goodsName},#{goodsTypeId},#{price},#{describle},#{picture})")
    int insertGoods(Goods goods);

    @Delete("delete from goods where id = #{id}")
    int deleteGoodsById(long id);

    @Delete("delete from goods where goodsTypeId = #{goodsTypeId}")
    int deleteAllGoodsByGoodsTypeId(long goodsTypeId);

    @Update("update goods set goodsName = #{goodsName}, goodsTypeId = #{goodsTypeId}, price = #{price}," +
            " describle = #{describle} where id = #{id}")
    int updateGoods(Goods goods);

    @Select("select * from goods")
    List<Goods> loadAllGoods();

    @Select("select * from goods where goodsTypeId = #{id}")
    List<Goods> loadGoodsById(long id);

    @Select("select * from goods where id = #{id}")
    Goods getGoodsById(long id);

    @Select("select * from goods_types where id = #{goodsTypeId}")
    GoodsType getGoodsTypeByTypeId(Long goodsTypeId);

    @Select("select * from goods where goodsName like #{goodsName}")
    List<Goods> findGoodsBySearch(String goodsName);

    //GoodsType
    @Insert("insert into goods_types(goodsType) values(#{goodsType})")
    int insertGoodsType(GoodsType goodsType);

    @Delete("delete from goods_types where id = #{id}")
    int deleteGoodsTypesById(long id);

    @Delete("delete from goods_types where goodsType = #{goodsType}")
    int deleteGoodsType(GoodsType goodsType);

    @Update("update goods_types set goodsType = #{goodsType}" +
            "where id = #{id}")
    int updateGoodsType(GoodsType goodsType);

    @Select("select * from goods_types")
    List<GoodsType> loadAllGoodsType();

    @Select("select id from goods_types where goodsType = #{goodsType}")
    int findGoodsTypeId(String goodsType);

    @Select("select * from goods_types where goodsType like #{goodsType}")
    List<GoodsType> findGoodsTypesBySearch(String goodsType);

    @Select("select count(*) from goods")
    Long countAllGoods();
}
